#include <iostream>

#include "ipc_client.h"

#include <thread>	// sleep_for

using namespace ipc;

// 服务器数据监听器(接口)
class ServerObserver : public IServerObserver, protected BundleHelper
{
public:
	// 服务器发送了监听的数据过来
	void onUpdate(Bundle& data) override
	{
		std::cout << getId(data) << ": " << getString(data) << std::endl;
	}
};

class ServiceConnectionListener : public IServiceConnectionListener
{
public:
	// 服务连接上了
	void onConnected(const std::string& serviceName) override
	{
		std::cout << "onConnected " << serviceName << std::endl;
	}
	
	// 服务断开了
	void onDisconnected(const std::string& serviceName)
	{
		std::cout << "onDisconnected " << serviceName << std::endl;
	}
};

ServerObserver observer;
ServiceConnectionListener listener;

int main()
{	
	IpcKit::init();
	
	Client::getInstance()->setServiceConnectionListener(&listener);
	Client::getInstance()->addServerObserverForId("Bt.number", &observer);
	Client::getInstance()->postString("Bt.dial", "10086");
	Client::getInstance()->postInt32("Radio.setFreq", 9050);
	
	IpcKit::join();
}

